Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New HCL AppScan on Cloud SAST parser #11375

Merged
merged 19 commits into from
Jan 23, 2025

Conversation

xpert98
Copy link

@xpert98 xpert98 commented Dec 4, 2024

⚠️ Note on feature completeness ⚠️

We are narrowing the scope of acceptable enhancements to DefectDojo in preparation for v3. Learn more here:
https://github.com/DefectDojo/django-DefectDojo/blob/master/readme-docs/CONTRIBUTING.md

Description

This is a new parser for HCL AppScan on Cloud SAST results.

Test results

Tests are included and pass.

Documentation

Documentation included.

Checklist

This checklist is for your information.

  • Make sure to rebase your PR against the very latest dev.
  • Features/Changes should be submitted against the dev.
  • Bugfixes should be submitted against the bugfix branch.
  • Give a meaningful name to your PR, as it may end up being used in the release notes.
  • Your code is flake8 compliant.
  • Your code is python 3.11 compliant.
  • If this is a new feature and not a bug fix, you've included the proper documentation in the docs at https://github.com/DefectDojo/django-DefectDojo/tree/dev/docs as part of this PR.
  • Model changes must include the necessary migrations in the dojo/db_migrations folder.
  • Add applicable tests to the unit tests.
  • Add the proper label to categorize your PR.

Extra information

@github-actions github-actions bot added settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR docs unittests parser labels Dec 4, 2024
Copy link

dryrunsecurity bot commented Dec 4, 2024

DryRun Security Summary

DefectDojo has added a new parser for HCL AppScan on Cloud SAST, updated application settings, and created a comprehensive test suite to enhance its security assessment capabilities.

Expand for full summary

Summary:

The provided code changes cover a range of updates to the DefectDojo application, including the addition of a new parser for the HCL AppScan on Cloud SAST (Static Application Security Testing) tool, updates to the application settings, and the introduction of a comprehensive test suite for the new parser.

From an application security perspective, the changes are generally positive and demonstrate a thoughtful approach to integrating new security tooling and ensuring the reliability of the security assessment process. Key highlights include:

  1. The addition of the HCL AppScan on Cloud SAST parser, which allows DefectDojo to ingest and process findings from this popular SAST tool. The parser's handling of XML parsing, security finding extraction, and populating the Finding object is well-designed and thorough.

  2. The updates to the application settings, which configure the deduplication algorithm for the new parser and ensure that findings are accurately identified and handled.

  3. The comprehensive test suite for the HCL AppScan on Cloud SAST parser, which covers various scenarios and validates the parser's ability to correctly process scan reports with no findings, a single finding, and multiple findings.

  4. The inclusion of sample scan reports, which demonstrate the parser's handling of real-world security issues, such as a privilege escalation vulnerability in a Dockerfile.

Overall, these changes demonstrate a strong focus on security and a commitment to providing a robust and reliable security assessment platform for the DefectDojo application.

Files Changed:

  1. docs/content/en/connecting_your_tools/parsers/file/hcl_asoc_sast.md: This new file provides documentation for the HCL AppScan on Cloud SAST parser, including information about the supported export formats and a link to sample scan data.

  2. dojo/tools/hcl_asoc_sast/__init__.py: This change adds an __author__ attribute to the file, which is a common practice in Python modules.

  3. dojo/tools/hcl_asoc_sast/parser.py: This file contains the implementation of the HCL AppScan on Cloud SAST parser, which includes XML parsing, security finding extraction, and populating the Finding object.

  4. unittests/scans/hcl_asoc_sast/no_issues.xml: This sample scan report indicates that no security issues were found in the "python-sample" application.

  5. dojo/settings/settings.dist.py: This change updates the DefectDojo application settings to add support for the HCL AppScan on Cloud SAST parser and configure the deduplication algorithm.

  6. unittests/tools/test_hcl_asoc_sast_parser.py: This file contains a comprehensive test suite for the HCL AppScan on Cloud SAST parser, covering various scenarios and validating the parser's functionality.

  7. unittests/scans/hcl_asoc_sast/one_issue.xml: This sample scan report includes a single security issue related to a privilege escalation vulnerability in a Dockerfile.

Code Analysis

We ran 9 analyzers against 8 files and 0 analyzers had findings. 9 analyzers had no findings.

View PR in the DryRun Dashboard.

@mtesauro
Copy link
Contributor

mtesauro commented Dec 4, 2024

@xpert98 Love the contribution but have to ask: Why are those conditionals so deeply nested?

I was reviewing this PR and wondering how much "fun" it would be to handle a future change with that deep nesting. I'm almost afraid to run a cyclical complexity tool on this parser code TBH.

Can you help me understand your thinking on that?

@xpert98
Copy link
Author

xpert98 commented Dec 4, 2024

@mtesauro I went that route because of the way the data is structured. Specifically for the mitigations and references, those are separate blocks outside of each result and that seemed like a convenient way to include the relevant "why it's a problem" and "how to fix it" into each issue to be rendered along with the typical issue details like file name and line number.

msg = "This doesn't seem to be a valid HCL ASoC SAST xml file."
raise NamespaceErr(msg)
report = root.find("issue-group")
if report is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of putting the whole function after this point inside an if block when report is not None, just bail if report is None.

Suggested change
if report is not None:
if report is None:
return findings

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was keeping the overall style of the parser similar to the existing hcl_appscan (for DAST) parser for consistency. I can refactor if this is a dealbreaker.

dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Dec 9, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@xpert98 xpert98 force-pushed the hcl-asoc-sast-parser branch from 8c9bdf7 to 6791149 Compare December 10, 2024 13:22
@mtesauro
Copy link
Contributor

@xpert98 Closing and re-opening to see if I can get ruff-linting unstuck

@mtesauro mtesauro closed this Dec 10, 2024
@mtesauro mtesauro reopened this Dec 10, 2024
@mtesauro
Copy link
Contributor

@mtesauro I went that route because of the way the data is structured. Specifically for the mitigations and references, those are separate blocks outside of each result and that seemed like a convenient way to include the relevant "why it's a problem" and "how to fix it" into each issue to be rendered along with the typical issue details like file name and line number.

HCL AppScan sure chose a "creative" structure for this output 🤮

@mtesauro
Copy link
Contributor

I'm approving assuming the sha256sum gets fixed before it's merged.

@xpert98 You'll be happy to see PR #11299 😉

Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
dojo/tools/hcl_asoc_sast/parser.py Outdated Show resolved Hide resolved
Copy link
Author

@xpert98 xpert98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorporating changes from @cneill

@mtesauro mtesauro merged commit feabd7b into DefectDojo:dev Jan 23, 2025
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs parser settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR unittests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants